<?php

namespace App\Services;

use App\Models\Escort;

/**
 * 通知服务
 * Class FileService
 * @package App\Services
 */
class NoticeService extends BaseService
{

    public static function send_order($order,$status=2,$url){

        $escort = Escort::find($order->escort_id);
        $post_data = [
            'platform' => 'GGPS',
            'out_trade_no' => $order->out_trade_no,
            'status' => $status,
            'escort' => [
                'name' => $escort->realname,
                'phone' => $escort->phone
            ],
        ];

        self::curl($url,["Content-Type: application/json"],$post_data);
    }

    public static function curl($gatewayUrl ,$headers=[], $postdata){

        $cl = curl_init($gatewayUrl);
        curl_setopt($cl, CURLOPT_POST, true);
        curl_setopt($cl,CURLOPT_HTTP_VERSION,CURL_HTTP_VERSION_1_1);
        curl_setopt($cl, CURLOPT_SSL_VERIFYPEER, false);  // 对认证证书来源的检查   // https请求 不验证证书和hosts
        curl_setopt($cl, CURLOPT_SSL_VERIFYHOST, false);  // 从证书中检查SSL加密算法是否存在
        curl_setopt($cl, CURLOPT_HTTPHEADER, $headers);
        curl_setopt($cl,CURLOPT_POSTFIELDS,json_encode($postdata));
        curl_setopt($cl,CURLOPT_RETURNTRANSFER,true);
        $content = curl_exec($cl);

        if (curl_errno($cl))
        {
            echo "Error: " . curl_error($cl);
        }
        curl_close($cl);
        $array = json_decode($content,1);
        return  $array;
    }
}
